package test21;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-12-14
 * Time: 17:34
 */
//根据月份进行排序
class CatComparator implements Comparator<Cat> {

    @Override
    public int compare(Cat o1, Cat o2) {
        return  o1.getMonth()- o2.getMonth();
    }
}
public class Main {


    public static void main(String[] args) {
        Cat huahua = new Cat("花花", 12, "英国短毛猫");
        Cat fanfan = new Cat("凡凡", 3, "中华田园猫");
        List<Cat> list = new ArrayList<>();
        list.add(huahua);
        list.add(fanfan);
        CatComparator catComparator = new CatComparator();
        Collections.sort(list,catComparator);
        System.out.println("按月份排序后");
        for (Cat cat :list) {
            System.out.println(cat.toString());
        }
    }
}
